## install.packages(c("tidyverse", "readxl"))
library(tidyverse)
library(readxl)

eip_turnout_time = read_excel("eip_turnout_time.xlsx") %>%
  mutate(midterm = case_when(year %in% c(1982, 1986, 1990, 1994, 1998, 2002, 2006, 
                                         2010, 2014, 2018) ~ 1,
                             TRUE ~ 0),
         values = values*100)

## Figure 1, Panel A ##
pres = ggplot(data=eip_turnout_time %>% filter(midterm == 0), aes(x=factor(year), y=values, group=factor(variable), color = factor(variable))) +
  geom_line() +
  scale_y_continuous(limits = c(0, 80), breaks = c(0, 20, 40, 60, 80),
                     labels = function(x) paste0(x, "%"))+
  labs(x = "Election", y = NULL) +
  scale_color_manual(name = NULL, values = c("blue", "red"),
                     labels = c("% Eligible to Vote Early", "Voter Turnout")) +
  scale_x_discrete(labels = c("1980", "1984", "1988", "1992", "1996", "2000", "2004", "2008", "2012", "2016", "2020")) +
  theme_bw() +
  theme(legend.position = "bottom")

## Figure 1, Panel B ##
midterm = ggplot(data=eip_turnout_time %>% filter(midterm == 1), aes(x=factor(year), y=values, group=factor(variable), color = factor(variable))) +
  geom_line() +
  scale_y_continuous(limits = c(0, 80), breaks = c(0, 20, 40, 60, 80),
                     labels = function(x) paste0(x, "%"))+
  labs(x = "Election", y = NULL) +
  scale_color_manual(name = NULL, values = c("blue", "red"),
                     labels = c("% Eligible to Vote Early", "Voter Turnout")) +
  scale_x_discrete(labels = c("1982", "1986", "1990", "1994", "1998", "2002", "2006", "2010", "2014", "2018")) +
  theme_bw() +
  theme(legend.position = "bottom")


